<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div class="container">
        <div class="content">垂直居中</div>
    </div>
    <style>
        .container {
            position: relative;
            height: 100vh;          /* 高度设为视口高度 */
            background-color: red;
        }
        .content {
            position: absolute;
            left: 50%;
            top: 50%;
            transform: translate(-50%, -50%); /* 将元素自身宽度、高度的一半往左和往上移动 */
            background-color: #ff69b4;
            padding: 20px;
            border-radius: 10px;
            color: white;
        }
    </style>
</body>
</html>